package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.pojo.TbAddress;
import com.guigu.qingcheng.service.OrderServiceFeign;
import com.guigu.qingcheng.service.UserServiceFeign;
import com.guigu.qingcheng.utils.JwtUtils;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AddressController {

    @Autowired
    private UserServiceFeign userServiceFeign;
    @Autowired
    private OrderServiceFeign orderServiceFeign;

    //跳转地址管理
    @GetMapping("/openAddress")
    public String openAddrs() {
        return "center-setting-address";
    }

    //获取当前用户所有地址
    @GetMapping("/queryAddressByUsername/{username}/{pageNum}/{pageSize}")
    @ResponseBody
    public R queryAddressByUsername(HttpServletRequest request,
                                    @PathVariable("username") String username,
                                         @PathVariable("pageNum") Integer pageNum
            , @PathVariable("pageSize") Integer pageSize
                                         ) {
        R r = userServiceFeign.pageQueryByAll(username, pageNum, pageSize);
        return r;
    }
    //根据用户名查询用户地址
    @GetMapping("/findByusername/{id}")
    @ResponseBody
    public R findByusername(@PathVariable("id") Integer id){
        R r = userServiceFeign.detail(id);
        return r;
    }

    //获取地址
    @GetMapping("/queryChenShi")
    @ResponseBody
    public R queryAddress(){
       R r =  orderServiceFeign.queryChenShi();
        return r;
    }
    //添加地址
    @PostMapping("/add")
    @ResponseBody
    public R add(@RequestBody TbAddress tbAddress){
        R r = userServiceFeign.add(tbAddress);
        return r;
    }
    //根据用户修改地址
    @PutMapping("/Updateaddresds")
    @ResponseBody
    public R Updateaddresds(@RequestBody TbAddress tbAddress){
        R r =userServiceFeign.update(tbAddress);
        return  r;
    }

    //删除地址
    @DeleteMapping("/deleteAddress/{id}")
    @ResponseBody
    public R deleteAddress(@PathVariable("id") Integer id){
        R r =userServiceFeign.delete(id);
        return r;
    }

    //根据省份id获取市
    @GetMapping("/queryShiById/{id}")
    @ResponseBody
    public R queryShiById(@PathVariable("id") String provinceid){
        R r=orderServiceFeign.queryShiById(provinceid);
        return r;
    }
    //获取区信息
    @GetMapping("/queryByQuId/{id}")
    @ResponseBody
    public R queryByQuId(@PathVariable("id") String provinceid){
        R r=orderServiceFeign.queryByQuId(provinceid);
        return r;
    }
    //修改默认地址
    @GetMapping("/updatetoAddress/{username}/{id}")
    @ResponseBody
    public R updatetoAddress(@PathVariable("username")String username,@PathVariable("id") Integer id){
        R r=userServiceFeign.updatetoAddress(username,id);
        return r;
    }
}
